var error=0;
var msg=new Array();


function username_validate(x)
{
	var myusername=/^[A-Za-z0-9_-]+$/;
	if(!myusername.test(x))
	{
		error=1;
		msg.push("username");

	}
}

function password_validate(x)
{
	var mypassword=/^[A-Za-z0-9_@#$%\^&+=]+$/;
	if(!mypassword.test(x))
	{
		error=1;
		msg.push("password");
	}
}
function rpassword_validate(x,y)
{
	
	if(x!=y)
	{
		error=1;
		alert("Password doesn't match");
		return false;
	}
	else
	{
		return true;
	}
}

function firstname_validate(x)
{
	var myfname=/^[A-Za-z]+$/;
	if(!myfname.test(x))
	{
		error=1;
		msg.push("firstname");
	}
}

function lastname_validate(x)
{
	var mylname=/^[A-Za-z]+$/;
	if(!mylname.test(x))
	{
		error=1;
		msg.push("lastname");
	}
}


function email_validate(x)
{
	var myemail=/^[A-Za-z0-9_.+-]+@[A-Za-z0-9_.+-]+\.[a-zA-Z0-9-.]+$/;
	if(!myemail.test(x))
	{
		error=1;
		msg.push("email");
    }
}


function main_validate()
{
	error=0;
	msg=new Array();
	var fname=document.getElementById('fname').value;
	var lname=document.getElementById('lname').value;
	var uname=document.getElementById('uname').value;
	var pword=document.getElementById('pword').value;
	var rpword=document.getElementById('rpword').value;
	var email= document.getElementById('email').value;
	username_validate(uname);
	password_validate(pword);
	firstname_validate(fname);
	lastname_validate(lname);
	email_validate(email);
	if(error==1)
	{
		var message="Invalid ";
		for(var i=0;i<msg.length;i++)
		{
			if(i==msg.length-1)
			{
				message=message+msg[i];
			}
			else
			{
				message=message+msg[i]+",";
			}   
						   
		}
		alert(message);
		return false;
	}
	else
	{
		return rpassword_validate(pword,rpword);
		
	}

}

